import React from 'react'
import { Text, View } from '@tarojs/components'
import style from './index.module.scss'
import { moduleUtil, track, jump } from '@conecli/cone-render/api'
import { LazyLoadImage } from '@conecli/cone-render/components'

const BasicModule = (props) => {
  const { floorData } = props
  const imageData = moduleUtil.getDataDefine(floorData, 'imageData')
  const textAreaData = moduleUtil.getDataDefine(floorData, 'textAreaData')
  const linkImageData = moduleUtil.getDataDefine(floorData, 'linkImageData')
  console.log("textAreaData:", textAreaData)
  console.log("imageData:", imageData)
  console.log("linkImageData:", linkImageData)
  /**
   * 跳转及坑位点击埋点
   * @param detail 模块链接跳转数据
   * @param event 原生click事件
   */
  const onClickLinkImage = (detail, event) => {
    console.log('detail:', detail)
    // TODO: 请务必进行判空处理，减少ISV模块引起的异常
    if(!detail || !floorData){
      return
    }
    // 埋点数据
    const trackEventInfo = track.getIsvClickEventInfo(floorData)
    console.log('trackEventInfo:', trackEventInfo)
    // 跳转逻辑
    jump.business.jdJumpConfigUrl(detail, trackEventInfo)
  }
  
  // 开发模块效果
  return (
    <View className={style['basicModule']}>
      <Text className={style['text-area']}>文本内容：{textAreaData.text}</Text>
      <LazyLoadImage
        className={style['d-img']}
        src={imageData?.imageUrl}
        lazyLoad={false}
        mode="widthFix"
      />
      <LazyLoadImage onClick={onClickLinkImage.bind(this, linkImageData?.data)}
        className={style['d-img-link']}
        src={linkImageData?.imageUrl}
        lazyLoad={false}
        mode="widthFix"
      />
    </View>
  )
}

export default BasicModule